﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.Admin;
using Shop.Model.Dto.Admin.Use;
using Shop.Model.View.Admin.User;

namespace Shop.AdminApi.Controllers;

/// <summary>
/// 用户管理服务
/// </summary>
[ApiController]
[Route("admin/[controller]")]
public class UseController: ShopControllerBase
{
    private readonly IUseService _useAppService;
    private readonly IUserContext _userContext;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="useAppService"></param>
    public UseController(IUseService useAppService,IUserContext userContext)
    {
        _useAppService = useAppService;
        _userContext = userContext;
    }
    
    /// <summary>
    /// 用户列表
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("UserList")]
    public AppResult<PageModel<UserListVo>> UserList([FromQuery] UserListDto dto)
        => _useAppService.UserList(dto);
    
    /// <summary>
    /// 用户状态(常量)
    /// </summary>
    /// <returns></returns>
    [HttpGet("UserState")]
    public AppResult<List<UserStateVo>> UserState()
    {
        var userStateVo = new List<UserStateVo>();
        var userStateOne = new UserStateVo(){Key = -2, Name = "封禁账号", Sort = 0};
        var userStateTwo = new UserStateVo(){Key = -1, Name = "注销账号", Sort = 1};
        var userStateThree = new UserStateVo(){Key = 0, Name = "正常", Sort = 2};
        var userStateFour = new UserStateVo(){Key = 1, Name = "冻结提现", Sort = 3};
        var userStateFive = new UserStateVo(){Key = 2, Name = "冻结账户", Sort = 4};
        userStateVo.Add(userStateOne);
        userStateVo.Add(userStateTwo);
        userStateVo.Add(userStateThree);
        userStateVo.Add(userStateFour);
        userStateVo.Add(userStateFive);
        return userStateVo;
    }
    
    /// <summary>
    /// 用户等级(常量)
    /// </summary>
    /// <returns></returns>
    [HttpGet("UserGrade")]
    public AppResult<List<UserGradeVo>> UserGrade()
    {
        var userGradeVo = new List<UserGradeVo>();
        var userGradeInfoOne = new UserGradeVo(){Key = -1, Name = "全部用户", Sort = 0};
        var userGradeInfoTwo = new UserGradeVo(){Key = 0, Name = "普通", Sort = 1};
        var userGradeInfoThree = new UserGradeVo(){Key = 1, Name = "会员", Sort = 2};
        var userGradeInfoFour = new UserGradeVo(){Key = 2, Name = "至尊", Sort = 3};
        var userGradeInfoFive = new UserGradeVo(){Key = 3, Name = "行家", Sort = 4};
        userGradeVo.Add(userGradeInfoOne);
        userGradeVo.Add(userGradeInfoTwo);
        userGradeVo.Add(userGradeInfoThree);
        userGradeVo.Add(userGradeInfoFour);
        userGradeVo.Add(userGradeInfoFive);
        return userGradeVo;
    }
    
    /// <summary>
    /// 调整推荐人前查询
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("ChangeSuperiorFront")]
    public AppResult<ChangeSuperiorFrontVo> ChangeSuperiorFront([FromQuery]int dto)
        => _useAppService.ChangeSuperiorFront(dto);
    
    /// <summary>
    /// 调整推荐人
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("ChangeSuperior")]
    public async Task<AppResult<bool>> ChangeSuperior(SuperiorChangeDto dto)
        => await _useAppService.ChangeSuperior(_userContext.Id,dto);
    
    /// <summary>
    /// 调整级别
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("ChangeGrade")]
    public AppResult UpUserGrade(UpUserGradeDto dto)
        => _useAppService.UpUserGrade(dto, _userContext.Id);

    /// <summary>
    /// 调整状态
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("UpUserState")]
    public AppResult UpUserState(UpUserStateDto dto)
        => _useAppService.UpUserState(dto);

    /// <summary>
    /// 用户明细
    /// </summary>
    /// <param name="uId"></param>
    /// <returns></returns>
    [HttpGet("UseInfo")]
    public AppResult<UseInfoVo> UseInfo([FromQuery] long uId)
        => _useAppService.UseInfo(uId);

    /// <summary>
    /// 用户钱包明细
    /// </summary>
    /// <param name="uId"></param>
    /// <returns></returns>
    [HttpGet("UseWellet")]
    public AppResult<PageModel<UseWelletVo>> UseWellet([FromQuery]UseWelletDto dto)
        => _useAppService.UseWellet(dto);

    /// <summary>
    /// 钱包调整
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("WelletAdjust")]
    public AppResult WelletAdjust(WelletAdjustDto dto)
        => _useAppService.WelletAdjust(dto, _userContext.Id);
}